package org.hamster.multidropbox.mainView.view
{
	import mx.utils.ArrayUtil;
	
	import org.hamster.common.puremvc.mediator.BaseMediator;
	import org.hamster.common.utils.ArrayUtils;
	import org.hamster.dropbox.DropboxEvent;
	import org.hamster.multidropbox.dropbox.event.AppDropboxEvent;
	import org.hamster.multidropbox.dropbox.model.DropboxLinkFoldersProxy;
	import org.hamster.multidropbox.dropbox.vo.AppDropboxClient;
	import org.hamster.multidropbox.dropbox.vo.AppDropboxLinkFoldersVO;
	import org.hamster.multidropbox.main.utils.PureMVCHelper;
	import org.hamster.multidropbox.mainView.event.MainViewEvent;
	
	public class LeftPanelViewMediator extends BaseMediator
	{
		public static const NAME:String = "org.hamster.multidropbox.mainView.view.LeftPanelViewMediator";
		
		public function LeftPanelViewMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void
		{
			app.linkFolderListDG.addEventListener(MainViewEvent.DATA_RENDERER_ITEM_CLICK, linkFolderItemClickHandler);
		}
		
		override public function onRemove():void
		{
			
		}
		
		private function linkFolderItemClickHandler(event:MainViewEvent):void
		{
			var linkFolderVO:AppDropboxLinkFoldersVO = event.data;
			this.sendNotification(MainViewEvent.LINK_FOLDERS_VIEW_SHOW, linkFolderVO);
			
		}
		
		override public function listNotificationInterests():Array
		{
			return [
				AppDropboxEvent.DROPBOX_CLIENT_CHANGE,
				AppDropboxEvent.DROPBOX_LINK_FOLDERS_CHANGE,
			];
		}
		
		public function handleDropboxClientChange(data:Object):void
		{
			app.accountList = ArrayUtils.clone(PureMVCHelper.dropboxClientListProxy.dropboxClientList);
		}
		
		public function handleDropboxLinkFoldersChange(data:Object):void
		{
			app.linkedFolderList = ArrayUtils.clone(PureMVCHelper.dropboxLinkFoldersProxy.dropboxLinkFoldersList);
		}
		
		
		public function get app():LeftPanelView
		{
			return viewComponent as LeftPanelView;
		}
	}
}